package cn.ffcs.uec.outStaffAdjustPostApply.component;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.IdSpace;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zkplus.databind.BindingListModelList;
import org.zkoss.zul.Div;
import org.zkoss.zul.ListModelList;

import cn.ffcs.raptornuke.plugin.common.zk.util.ZkUtil;
import cn.ffcs.uec.outStaffAdjustPostApply.component.bean.UecWaCrtListboxExtBean;
import cn.ffcs.uec.salary.manager.UecWaCrtManager;
import cn.ffcs.uec.salary.model.UecWaCrt;
import cn.ffcs.uom.common.util.ApplicationContextUtil;
import cn.ffcs.uom.common.util.IPortletInfoProvider;
import cn.ffcs.uom.common.util.ListboxUtils;
import cn.ffcs.uom.common.util.NumericUtil;
import cn.ffcs.uom.common.util.PubUtil;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.vo.PageInfo;
import lombok.Getter;
import lombok.Setter;

@Controller
@Scope("prototype")
public class UecWaCrtListboxExt extends Div implements IdSpace {

	private static final long serialVersionUID = 2919703049304796779L;

	private UecWaCrtListboxExtBean bean = new UecWaCrtListboxExtBean();

	/**
	 * zul
	 */
	private static final String ZUL = "/pages_nmg/uec_salary/comp/uecWaCrtBandbox/uecWaCrt_listbox_ext.zul";

	/**
	 * 薪资标准
	 */
	private UecWaCrt uecWaCrt;

	private UecWaCrtManager uecWaCrtManager = (UecWaCrtManager) ApplicationContextUtil.getBean("uecWaCrtManager");

//	private UecOutStaffInfo uecOutStaffInfo;

	@Getter
	@Setter
	private IPortletInfoProvider portletInfoProvider;

	public UecWaCrtListboxExt() {
		// 1.绑定页面
		Executions.createComponents(ZUL, this, null);
		// 2.页面控件与java属性绑定
		Components.wireVariables(this, bean);
		// 3.绑定监听事件
		Components.addForwards(this, this, '$');

	}

	/**
	 * 触发选中事件
	 */
	public void onSelectRequest() throws Exception {
		if (bean.getUecWaCrtListbox().getSelectedCount() > 0) {
			uecWaCrt = (UecWaCrt) bean.getUecWaCrtListbox().getSelectedItem().getValue();
			Events.postEvent("onSelectUecWaCrt", this, uecWaCrt);
		} else {
			Events.postEvent("onSelectNoUecWaCrt", this, null);
		}
	}

	public void onQuery() {
		uecWaCrt = new UecWaCrt();
		PubUtil.fillPoFromBean(bean, uecWaCrt);
		this.queryUecWaCrtInfo();
	}

	/**
	 * 查询
	 */
	public void queryUecWaCrtInfo() {
		if (!StrUtil.isNullOrEmpty(uecWaCrt.getPostGrade())) {
			int activePage = bean.getUecWaCrtListboxPaging().getActivePage();
			int pageSize = bean.getUecWaCrtListboxPaging().getPageSize();
			PageInfo pageInfo = uecWaCrtManager.queryPageInfoByUecWaCrt(uecWaCrt, activePage + 1, pageSize);
			ListModelList dataList = new BindingListModelList(pageInfo.getDataList(), true);
			bean.getUecWaCrtListbox().setModel(dataList);
			bean.getUecWaCrtListboxPaging().setTotalSize(NumericUtil.nullToZero(pageInfo.getTotalCount()));
		}else {
			ZkUtil.showInformation("请填写岗位等级进行查询", "温馨提示");
		}
	}

	/**
	 * 重置
	 */
	public void onReset() {
		clearVariable();
		bean.getPostGrade().setValue(null);
		//bean.getWaCrtMoney().setValue(null);
		//bean.getWaCrtName().setValue(null);
		ListboxUtils.clearListbox(this.bean.getUecWaCrtListbox());
		this.bean.getUecWaCrtListboxPaging().setTotalSize(1);
	}

	/**
	 * 清除变量
	 */
	public void clearVariable() {
		uecWaCrt = null;
	}

	/**
	 * 翻页
	 */
	public void onUecWaCrtListboxPaging() {
		this.queryUecWaCrtInfo();
	}

}
